<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 8/6/2015
 * Time: 11:36 AM
 */
define('BIZWEBSKY_PARENT_URL', get_template_directory_uri());
define('BIZWEBSKY_JS_URL', BIZWEBSKY_PARENT_URL . '/js');

/**
 * Register widget area.
 *
 * @link http://codex.wordpress.org/Function_Reference/register_sidebar
 */
function bizwebsky_widgets_init()
{
	register_sidebar(array(
		'name' => esc_html__('Main Sidebar', 'bizwebsky'),
		'id' => 'main-sidebar',
		'description' => '',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	));
	register_sidebar(array(
		'name' => esc_html__('Footer Top Collum 1', 'bizwebsky'),
		'id' => 'footer-top-col-1',
		'description' => '',
		'before_widget' => '<div class="col-lg-3 col-md-3 col-sm-6">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>',
	));
	register_sidebar(array(
		'name' => esc_html__('Footer Top Collum 2', 'bizwebsky'),
		'id' => 'footer-top-col-2',
		'description' => '',
		'before_widget' => '<div class="col-lg-3 col-md-3 col-sm-6">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>',
	));
	register_sidebar(array(
		'name' => esc_html__('Footer Top Collum 3', 'bizwebsky'),
		'id' => 'footer-top-col-3',
		'description' => '',
		'before_widget' => '<div class="col-lg-3 col-md-3 col-sm-6">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>',
	));
	register_sidebar(array(
		'name' => esc_html__('Footer Top Collum 4', 'bizwebsky'),
		'id' => 'footer-top-col-4',
		'description' => '',
		'before_widget' => '<div class="col-lg-3 col-md-3 col-sm-6">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>',
	));
	register_sidebar(array(
		'name' => esc_html__('Footer Bot Collum 1', 'bizwebsky'),
		'id' => 'footer-bot-col-1',
		'description' => '',
		'before_widget' => '<div class="col-lg-3 col-md-3 col-sm-4">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>',
	));
	register_sidebar(array(
		'name' => esc_html__('Footer Bot Collum 2', 'bizwebsky'),
		'id' => 'footer-bot-col-2',
		'description' => '',
		'before_widget' => '<div class="col-sm-9 col-md-9">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>',
	));

	register_sidebar(array(
		'name' => esc_html__('Nhân viên hỗ trợ', 'bizwebsky'),
		'id' => 'cmp-wg-support',
		'description' => '',
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '',
		'after_title' => '',
	));
	register_sidebar(array(
		'name' => esc_html__('Ý kiến khách hàng', 'bizwebsky'),
		'id' => 'cmp-wg-customer',
		'description' => '',
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '',
		'after_title' => '',
	));
}

add_action('widgets_init', 'bizwebsky_widgets_init');

add_action('admin_enqueue_scripts', 'colormag_image_uploader');
function colormag_image_uploader()
{
	wp_enqueue_media();
	wp_enqueue_script('colormag-widget-image-upload', BIZWEBSKY_JS_URL . '/image-uploader.js', false, '20150309', true);
}

//Shortcode register
// [register text="Đăng ký"]
function register_func($atts)
{
	extract(shortcode_atts(array(
		'text' => 'Dùng thử miễn phí'
	), $atts));
	$str = '<section class="register">
				<div class="container">
					<div class="row">
						<p class="text">Bắt kịp nhu cầu toàn thế giới, đăng ký dùng thử miễn phí ngay từ bây giờ</p>
							<form action="javascript:void(0)" class="register-form">
								<div class="enterprise-name">
									<input type="text" placeholder="Nhập tên cửa hàng/doanh nghiệp của bạn">
								</div>
								<a href="#" class="trial popup-control">' . $text . '</a>
							</form>
						</div>
					</div>
			</section>';
	return $str;
}

add_shortcode('register', 'register_func');

function custom_excerpt_length( $length ) {
	return 45;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

function my_search_form( $form ) {
	$form = '<form class="frm-search" role="search" method="get" action="http://blog.sapo.vn/">
        <input class="txt-search" type="text" value="" placeholder="Tìm kiếm..." name="s" id="s">
        <input id="searchsubmit" class="btn-search" value="" type="submit">
      </form>';

	return $form;
}

add_filter( 'get_search_form', 'my_search_form' );

function custom_length_excerpt($word_count_limit) {
	$content = wp_strip_all_tags(get_the_content() , true );
	echo wp_trim_words($content, $word_count_limit);
}